/*
 * BinaryRule.java
 *
 * Created on June 25, 2006, 8:42 PM
 *
 */

package galronnlp.pcfg.grammar;

import galronnlp.util.Symbol;

import java.util.List;
import java.util.LinkedList;

/**
 *
 * @author Daniel A. Galron
 */
public class BinaryRule implements Rule {
    
    private final int arity = 2;
    private LinkedList<Symbol> RHS;
    private Symbol LHS;
    private double probability;
    
    /** Creates a new instance of BinaryRule */
    public BinaryRule(Symbol LHS, LinkedList<Symbol> RHS, double probability) {
        this.LHS = LHS;
        this.RHS = RHS;
        this.probability = probability;
    }

    public double prob() {
        return this.probability;
    }

    public double logProb() {
        return java.lang.Math.log(probability);
    }

    public int arity() {
        return this.arity;
    }

    public Symbol LHS() {
        return this.LHS;
    }

    public List<Symbol> RHS() {
        return this.RHS;
    }
    
    public String toString() {
        String ret = this.LHS + " --> " + this.RHS.get(0) + ", " + this.RHS.get(1) + ": " + this.probability;
        return ret;
    }    

    public boolean hasTerminalRHS() {
        return false;
    }
    
}
